﻿#include "midregionform.h"
#include "ui_midregionform.h"

midregionForm::midregionForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::midregionForm)
{
    ui->setupUi(this);
    this->setObjectName("WidgetObjectregionwatvch-aaa");
    this->setWindowTitle(tr("midregionform"));
}

midregionForm::~midregionForm()
{
    delete ui;
}
void midregionForm::generateTask(TaskItem *pTask)
{

}

void midregionForm::on_pushButton_AddRegion_clicked()
{

}

void midregionForm::on_pushButton_RemoveRegion_clicked()
{

}

void midregionForm::on_pushButton_AddCycle_clicked()
{

}

void midregionForm::on_pushButton_DeCycle_clicked()
{

}

void midregionForm::on_pushButton_CalPos_clicked()
{

//    //给出中心区域x，y算出下面四个数

//    double dEWMin = 中心x-区域范围长度/2;
//    double dEWMax = 中心x+区域范围长度/2;
//    double dNSMin = 中心y-区域高度/2;
//    double dNSMax = 中心y+区域高度/2;

//    //以下不变
//    double dMirrHeight = TaskManager::getInstance()->currentInstrument()->mdMirrorHeight;
//    double dMirrLeftHalf = TaskManager::getInstance()->currentInstrument()->mdMirrorLeftHalf;;
//    double dMirrRightHalf = TaskManager::getInstance()->currentInstrument()->mdMirrorRightHalf;;

//    // 清空行
//    while(ui->tableWidget->rowCount()> 0)
//    {
//        ui->tableWidget->removeRow(0);
//    }
//    //扫描行号，等于扫描范围y/500*1024（镜子像素）
//    int ScanRowNumber = ceil((dNSMax-dNSMin) / dMirrHeight);
//    if(ui->comboBox_RegionMode->currentIndex() > 1)// 往返扫描模式
//    {
//        ScanRowNumber = ScanRowNumber%2 == 0? ScanRowNumber:ScanRowNumber+1;
//    }

//    // 实际观测的区域高度
//    double dRealHeight = dMirrHeight * ScanRowNumber;

//    // 中间对齐
//    if(ui->comboBox_PosAlign->currentIndex() == 0)
//    {
//        dNSMax = (dNSMin+dNSMax)/2 + dRealHeight/2;
//        dNSMin = dNSMax - dRealHeight;
//    }
//    // 大数对齐，北侧，正向
//    else if(ui->comboBox_PosAlign->currentIndex() == 0)
//    {
//        dNSMin = dNSMax - dRealHeight;
//    }
//    // 小数对齐
//    else
//    {
//        dNSMax = dNSMin + dRealHeight;
//    }

//    ui->tableWidget->setRowCount(ScanRowNumber);

//    double dMaxSpeed = ui->doubleSpinBox_ScanSpeed->value();
//    double dAccRedTime = 0.1;// 加/减速时间，加减速需要乘以2
//    double dAccRedDis = dMaxSpeed * dAccRedTime / 2.0;// 加/减速段距离
//    double dStabTime = 0.2;// 稳定段时间
//    double dStabDis = dStabTime * dMaxSpeed;// 稳定段距离

//    double dAlighTime = ui->doubleSpinBox_align->value();

//    // 该行代码，按照实际扫描区域的中间位置计算
//    double dCenterEW = (dEWMax+dEWMin) / 2.0;// 东西向中间位置
//#if 1// 下述代码，计算了实际的中间位置，并按照单行和往返扫描模式计算
//    if(ui->comboBox_RegionMode->currentIndex() > 1)// 往返扫描模式
//    {
//        dCenterEW = (dEWMax+dEWMin+dMirrLeftHalf-dMirrRightHalf) / 2.0;// 东西向中间位置
//    }
//    else
//    {
//        // 单行扫描模式
//        dCenterEW = (dEWMax+dEWMin+dMirrLeftHalf-dMirrRightHalf-dStabDis) / 2.0;// 东西向中间位置
//    }
//#endif

//    // 圆形
//    if(ui->comboBox_RegionMode->currentIndex() == 0)
//    {
//        double dCircleR = qMax(dNSMax-dNSMin,dEWMax-dEWMin) / 2.0;// 圆形半径
//        for(int i=0; i<ScanRowNumber; ++i)
//        {
//            double dLineEWHalf = sqrt(dCircleR*dCircleR - (dNSMax-i*dMirrHeight-dMirrHeight/2.0)*(dNSMax-i*dMirrHeight-dMirrHeight/2.0));

//            double dTotTime = dAccRedTime*2+dStabTime+(dLineEWHalf*2 + dMirrRightHalf + dMirrLeftHalf)/dMaxSpeed;

//            ui->tableWidget->setItem(i,0,new QTableWidgetItem(tr("%1 %2").arg(msCurTaskName).arg(i+1)));
//            ui->tableWidget->setItem(i,1,new QTableWidgetItem(QString::number(dCenterEW-dLineEWHalf-dAccRedDis-dStabDis-dMirrRightHalf,'f',6)));
//            ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(dCenterEW+dLineEWHalf+dAccRedDis+dMirrLeftHalf,'f',6)));
//            ui->tableWidget->setItem(i,3,new QTableWidgetItem(QString::number(dNSMax-i*dMirrHeight-dMirrHeight*0.5,'f',6)));
//            ui->tableWidget->setItem(i,4,new QTableWidgetItem(QString::number(dNSMax-i*dMirrHeight-dMirrHeight*0.5,'f',6)));

//            //  中间时间对齐
//            if(ui->comboBox_TimeAlign->currentIndex() == 0)
//            {
//                ui->tableWidget->setItem(i,5,new QTableWidgetItem(QString::number(dAlighTime - dTotTime*0.5,'f',6)));
//                ui->tableWidget->setItem(i,6,new QTableWidgetItem(QString::number(dAlighTime,'f',6)));
//                ui->tableWidget->setItem(i,7,new QTableWidgetItem(QString::number(dAlighTime + dTotTime*0.5,'f',6)));
//                ui->tableWidget->setItem(i,8,new QTableWidgetItem(QString::number(dTotTime,'f',6)));
//            }
//            // 开始时间对齐
//            else if(ui->comboBox_TimeAlign->currentIndex() == 1)
//            {
//                ui->tableWidget->setItem(i,5,new QTableWidgetItem(QString::number(dAlighTime,'f',6)));
//                ui->tableWidget->setItem(i,6,new QTableWidgetItem(QString::number(dAlighTime + dTotTime*0.5,'f',6)));
//                ui->tableWidget->setItem(i,7,new QTableWidgetItem(QString::number(dAlighTime + dTotTime,'f',6)));
//                ui->tableWidget->setItem(i,8,new QTableWidgetItem(QString::number(dTotTime,'f',6)));
//            }
//            // 结束时间对齐
//            else
//            {
//                ui->tableWidget->setItem(i,5,new QTableWidgetItem(QString::number(dAlighTime - dTotTime,'f',6)));
//                ui->tableWidget->setItem(i,6,new QTableWidgetItem(QString::number(dAlighTime - dTotTime*0.5,'f',6)));
//                ui->tableWidget->setItem(i,7,new QTableWidgetItem(QString::number(dAlighTime,'f',6)));
//                ui->tableWidget->setItem(i,8,new QTableWidgetItem(QString::number(dTotTime,'f',6)));
//            }

//            dAlighTime += ui->doubleSpinBox_Cycle->value();

//        }

//    }


//    on_comboBox_TimeAlign_currentIndexChanged(ui->comboBox_TimeAlign->currentIndex());
}

void midregionForm::on_comboBox_TimeAlign_currentIndexChanged(int index)
{

}

void midregionForm::on_tableWidget_Command_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
{
}
